#pragma once
#include "util.hpp" //要读取配置文件初始化,所以要用该头文件
#include <string>
namespace cloud
{
#define CONFIG_FILE "./cloud.conf"
    class Config
    {
    private:
        Config()
        {
            ReadConfigfile();
        }
        int hot_time_;
        int serverport_;
        std::string serverip_;
        std::string download_prefix_; // 下载路径
        std::string packfile_suffix_; //压缩文件后缀
        std::string back_file_;   // 备份文件路径
        std::string pack_file_;   // 压缩文件路径
        std::string backup_file_; // 文件属性信息备份路径
        bool ReadConfigfile()     // 读取配置文件信息初始化成员
        {
            Fileutil fu(CONFIG_FILE);
            std::string body;
            if (fu.GetContent(&body) == false)
            {
                FATAL("ReadConfig: Get content err  错误码: %d 错误消息: %s",errno,strerror(errno));                
                return false;
            }
            Json::Value js;
             if (Jsonutil::Unserialize(body, &js) == false)
            {
                FATAL("ReadConfig: Unserialize err 错误码: %d 错误消息: %s",errno,strerror(errno));                
                return false;
            };
            hot_time_ = js["hot_time"].asInt();
            serverport_ = js["serverport"].asInt();
            serverip_ = js["serverip"].asString();
            download_prefix_ = js["download_prefix"].asString(); // 下载路径
            packfile_suffix_ = js["packfile_suffix"].asString();
            back_file_ = js["back_file"].asString();   // 备份文件路径
            pack_file_ = js["pack_file"].asString();   //
            backup_file_ = js["backup_file"].asString();  // 文件属性信息备份路径
            return true;
        }

    public:
        static Config *GetInstance()
        {
            static Config cfg;
            return &cfg;
        }

        int GetHotime()
        {
            return hot_time_;
        }
        int GetPort()
        {
            return serverport_;
        }
        std::string GetIp()
        {
            return serverip_;
        }
        std::string GetDprefix()
        {
            return download_prefix_;
        }
        std::string GetPacksuffix()
        {
            return packfile_suffix_;
        }
        std::string GetBackfile()
        {
            return back_file_;
        }
        std::string GetPackfile()
        {
            return pack_file_;
        }
        std::string GetBackUpfile()
        {
            return backup_file_;
        }
    };
};